package cn.dengta.webapp.trade.vo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import cn.dengta.common.model.Status;
import cn.dengta.common.util.Formats;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.trade.entity.UserIntegralLog;
import cn.dengta.webapp.trade.model.*;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.*;

/**
 * 钻石流水记录表
 *
 * @author yuqidi
 * @since 2022-03-18
 */
@Setter
@Getter
public class UserIntegralLogVO extends AbstractVO<UserIntegralLog> {

	/** 资金流向：1=收入；0=不变；-1=支出 Flow */
	protected Integer flow;
	/** 交易额度 */
	protected BigDecimal tradeAmount;
	/** 免费钻部分所得积分 */
	protected BigDecimal freeAmount;
	/** 资金积分 */
	protected BigDecimal totalAmount;
	/** 可用积分 */
	protected BigDecimal activeAmount;
	/** 冻结积分 */
	protected BigDecimal frozenAmount;
	/** 业务类型 */
	protected String tradeType;
	/** 钻石收益来源类型 */
	protected String coinTradeType;
	/** 处理状态 */
	protected Integer handleStatus;
	/** 处理状态 */
	protected String handleStatus_;
	/** 备注 */
	protected String remark;
	/** 自定义类型 */
	protected String subject;
	/** 是否已再利用: 0=没有(默认);1=已使用 */
	protected Integer useStatus;
	/** 提现金额 */
	protected BigDecimal realAmount;

	/** 用户 */
	protected Map<String, Object> user;
	protected Map<String, Object> agent;
	/** 用户 */
	protected Map<String, Object> toUser;
	protected Map<String, Object> toAgent;

	public static UserIntegralLogVO fromFront(UserIntegralLog source) {
		return copy(source, UserIntegralLogVO::new, "addTime_", "tradeAmount_", "totalAmount_", "activeAmount_", "frozenAmount_");
	}

	public static UserIntegralLogVO from(UserIntegralLog source) {
		return copy(source, UserIntegralLogVO::new);
	}

	public String getFlow_() {
		return X.map(Flow.of(flow), Flow::getLabel);
	}

	public String getTradeType_() {
		return X.map(TradeType.of(tradeType), TradeType::getLabel);
	}

	public String getHandleStatus_() {
		if (StringUtil.notEmpty(handleStatus_)) {
			return handleStatus_;
		}
		return X.map(HandleStatus.of(handleStatus), HandleStatus::getLabel);
	}

	public Date getAddTime() {
		return super.getAddTime();
	}

	public String getAddTime_() {
		return super.getAddTime_();
	}

	public String getTradeAmount_() {
		return Formats.formatNumber_D(tradeAmount);
	}

	public String getTotalAmount_() {
		return Formats.formatNumber_D(totalAmount);
	}

	public String getActiveAmount_() {
		return Formats.formatNumber_D(activeAmount);
	}

	public String getFrozenAmount_() {
		return Formats.formatNumber_D(frozenAmount);
	}

	public String getDay_() {
		return Formats.formatDate_D(this.addTime);
	}

	public String getFreeAmount_() {
		if (!Flow.INCOME.eq(this.flow) || this.freeAmount == null || this.freeAmount.compareTo(BigDecimal.ZERO) == 0) {
			return null;
		}
		return "赠送" + freeAmount + "积分";
	}

	/** 是否可用 */
	public Boolean getHasUse() {
		return Status.NO.eq(useStatus) && System.currentTimeMillis() < this.getAddTime().getTime() + EasyDate.MILLIS_OF_DAY * 2;
	}

}
